package com.qianfeng.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.dto.Page;
import com.qianfeng.entity.Cls;
import com.qianfeng.mapper.ClassMapper;
import com.qianfeng.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class ClassServiceImpl implements ClassService {

    @Autowired
    private ClassMapper classMapper;

    @Override
    public void addClass(Cls cls) {
        classMapper.addClass(cls);
    }

    @Override
    public void deleteClass(Integer classId) {
        classMapper.deleteClass(classId);
    }

    @Override
    public void updateClass(Cls cls) {
        classMapper.updateClass(cls);
    }

    @Override
    public List<Cls> getClassList() {
        List<Cls> classList = classMapper.getClassList();

        return classList;
    }

    @Override
    public List<Cls> getClassByClassId(Integer classId) {
        List<Cls> classByClassId = classMapper.getClassByClassId(classId);

        return classByClassId;
    }

    @Override
    public Page getClassPage(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<Cls> classList = classMapper.getClassList();
        Page page = new Page();
        PageInfo<Cls> pageInfo = new PageInfo<>(classList);
        page.setCount(pageInfo.getTotal());
        page.setPages(pageInfo.getPages());
        page.setObj(pageInfo.getList());
        return page;
    }
}
